package com.astruyk.battlegroundAndroid;

import java.util.Random;

import com.astruyk.battlegroundAndroid.data.CapturePoint;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Picture;
import android.os.Bundle;
import android.view.View;

public class CanvasMapActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Cursor cpCursor = managedQuery(
				CapturePoint.CONTENT_URI,
				new String[] { CapturePoint._ID },
				null,
				null,
				null);
		setContentView(new SampleView(this, cpCursor));
	}	
	
	 private static class SampleView extends View {
	        private Picture mPicture;
	        private int count;
	       
	        public SampleView(Context context, Cursor cpCursor) {
	            super(context);
	            setFocusable(true);
	            setFocusableInTouchMode(true);

	            mPicture = new Picture();
	            drawSomething(mPicture.beginRecording(200, 100));
	            mPicture.endRecording();
	            
	            count = cpCursor.getCount();
	        }
	        
	        static void drawSomething(Canvas canvas) {
	            Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
	            p.setColor(0x88FF0000);
	            canvas.drawCircle(2.5f, 2.5f, 5, p);
	        }
	        
	        @Override protected void onDraw(Canvas canvas) {
	        	int maxX = this.getWidth();
	        	int maxY = this.getHeight();
	        	Random r = new Random();
	        	
	           for(int i = 0; i < count; i++){
	        	   int x = r.nextInt(maxX);
	        	   int y = r.nextInt(maxY);
	        	   
	        	   canvas.save();
	        	   canvas.translate(x,y);
	        	   canvas.drawPicture(mPicture);
	        	   canvas.restore();
	           }
	        }
	    }
}
